package com.situ.vivamarket.util;

import lombok.Getter;
import lombok.Setter;

@Getter
public class JsonResult {
    private final int code;//成功响应
    private final Object data;
    private final boolean success;
    private final String msg;
    @Setter
    private int count;//记录总数

    public void setCount(int count) {
        this.count = count;
    }

    public JsonResult(int code, boolean success, String msg, Object data) {
        this.code = code;
        this.data = data;
        this.success = success;
        this.msg = msg;
    }

    public static JsonResult successData(Object data) {
        return new JsonResult(0, true, null, data);
    }

    public static JsonResult fail(String msg) {
        return new JsonResult(-1, false, msg, null);
    }

    public static JsonResult fail() {
        return fail(null);
    }

    public static JsonResult success(String msg) {
        return new JsonResult(0, true, msg, null);
    }
}
